//package com.qttaudio.example.adapter;
//
//import android.content.Context;
//import android.support.v4.widget.PopupWindowCompat;
//import android.util.Log;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.view.animation.Animation;
//import android.view.animation.AnimationUtils;
//import android.widget.BaseAdapter;
//import android.widget.ImageView;
//import android.widget.TextView;
//
//import com.qttaudio.example.R;
//import com.qttaudio.example.config.Config;
//import com.qttaudio.example.data.MicSeatBean;
//import com.qttaudio.example.dialog.MicPopupWindow;
//import com.qttaudio.example.utils.GlideUtil;
//
//import java.util.Map;
//
//public class MicItemAdapter extends BaseAdapter {
//    private static String TAG = MicItemAdapter.class.getSimpleName();
//        private Context mContext;
//        private Map<Integer,MicSeatBean> seatMap;
//        private int count = Config.RoomSeatCount;
//        private MicPopupWindow.PopOnclick popOnclick;
//
//        public MicItemAdapter(Context context, Map<Integer,MicSeatBean> seatMap,MicPopupWindow.PopOnclick popOnclick) {
//            this.mContext = context;
//            this.seatMap = seatMap;
//            this.popOnclick = popOnclick;
//        }
//
//
//        @Override
//        public int getCount() {
//            return count;
//        }
//
//        @Override
//        public Object getItem(int position) {
//            return seatMap.get(position);
//        }
//
//        @Override
//        public long getItemId(int position) {
//            return position;
//        }
//
//        @Override
//        public View getView(int position, View convertView, ViewGroup parent) {
//            ViewHolder viewHolder = null;
//
//            if (convertView == null) {
//                convertView = LayoutInflater.from(mContext).inflate(R.layout.item_room_mic_list, parent, false);
//                viewHolder = new ViewHolder();
//                viewHolder.iv_mic_img = (ImageView) convertView.findViewById(R.id.iv_mic_img);
//                viewHolder.iv_mic_speaking_img = (ImageView) convertView.findViewById(R.id.iv_mic_speaking_img);
//                viewHolder.tv_user_name = (TextView) convertView.findViewById(R.id.tv_user_name);
//                viewHolder.iv_mic_state = (ImageView) convertView.findViewById(R.id.iv_mic_state);
//                convertView.setTag(viewHolder);
//            } else {
//                viewHolder = (ViewHolder) convertView.getTag();
//            }
//            MicSeatBean micSeatBean = null;
//            if (seatMap != null && seatMap.size() > position) {
//                micSeatBean = seatMap.get(position);
//            }
//
//            if (micSeatBean == null) {
//                viewHolder.iv_mic_state.setVisibility(View.GONE);
//                viewHolder.tv_user_name.setVisibility(View.INVISIBLE);
//                viewHolder.iv_mic_speaking_img.setVisibility(View.GONE);
//                viewHolder.iv_mic_img.setImageResource(R.drawable.layer_room_mic_item_normal);
//            } else {
//                GlideUtil.loadMicHeadUrl(mContext, viewHolder.iv_mic_img, micSeatBean.getHead_url());
//                viewHolder.tv_user_name.setVisibility(View.VISIBLE);
//                viewHolder.tv_user_name.setText(micSeatBean.getUsername() != null ? micSeatBean.getUsername() : "");
//                setMicStateView(viewHolder.iv_mic_state, micSeatBean);
//                setMicSpeaking(viewHolder.iv_mic_speaking_img, micSeatBean);
//            }
//            setOnclick(position,viewHolder, micSeatBean);
//
//            return convertView;
//        }
//
//        private void setOnclick(final int position,final ViewHolder viewHolder, final MicSeatBean micSeatBean) {
//            viewHolder.iv_mic_img.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    MicPopupWindow mWindow = new MicPopupWindow(mContext,position, micSeatBean);
//                    mWindow.setPopOnclick(popOnclick);
//                    View contentView = mWindow.getContentView();
//                    contentView.measure(0, 0);
//                    int offsetX = (viewHolder.iv_mic_img.getWidth() - mWindow.getContentView().getMeasuredWidth()) / 2;
//                    int offsetY = 0;
//                    PopupWindowCompat.showAsDropDown(mWindow, viewHolder.iv_mic_img, offsetX, offsetY, Gravity.START);
//
//                }
//            });
//
//
//        }
//
//        public void setMicStateView(ImageView imageView, MicSeatBean micSeatBean) {
//            if (micSeatBean.isMute() > 0) {
//                imageView.setVisibility(View.VISIBLE);
//                imageView.setBackgroundResource(R.drawable.shape_room_mic_item_state_bg);
//                imageView.setImageResource(R.drawable.layer_room_mic_item_no_mic);
//            } else if (micSeatBean.isMute()) {
//                imageView.setVisibility(View.VISIBLE);
//                imageView.setBackgroundResource(R.drawable.shape_room_mic_item_state_bg);
//                imageView.setImageResource(R.drawable.layer_room_mic_item_no_voice);
//            } else if (micSeatBean.isPrivate_chat() > 0) {
//                imageView.setVisibility(View.VISIBLE);
//                imageView.setBackgroundResource(R.drawable.shape_room_mic_item_state_two_bg);
//                imageView.setImageResource(R.mipmap.room_ear);
//            } else {
//                imageView.setVisibility(View.GONE);
//            }
//
//            Log.i("k_test", "user:" + micSeatBean.getUsername() + "  no_voice:" + micSeatBean.isMute() + " ");
//
//        }
//
//        public void setMicSpeaking(ImageView imageView, MicSeatBean micSeatBean) {
//            if (micSeatBean.getSpeaking() > 0) {
//                imageView.setVisibility(View.VISIBLE);
//                Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.anima_room_mic_speaking);
//                imageView.startAnimation(animation);
//            } else {
//                Animation animation = imageView.getAnimation();
//                if (animation != null) {
//                    animation.cancel();
//                    imageView.clearAnimation();
//                }
//                imageView.setVisibility(View.GONE);
//            }
//        }
//
//        class ViewHolder {
//            ImageView iv_mic_img;
//            ImageView iv_mic_speaking_img;
//            TextView tv_user_name;
//            ImageView iv_mic_state;
//        }
//    }